import requests

from config import BASE_URL


class ContractAPI:
    def __init__(self):
        self.upload_contract_url = BASE_URL + "/api/common/upload"
        self.add_contract_url = BASE_URL + "/api/contract"

    def upload_contract(self, token, data):
        headers = {"Authorization": token}
        file_data = {"file": data}
        response = requests.post(self.upload_contract_url, files=file_data, headers=headers)
        return response

    def add_contract(self, token, name="测试888", phone="13612341888",
                     contractNo="HT10012004", subject="6",
                     courseId=99, channel="0", activityId=77, fileName=""):
        headers = {"Authorization": token}
        add_contract_data = {
            "name": name,
            "phone": phone,
            "contractNo": contractNo,
            "subject": subject,
            "courseId": courseId,
            "channel": channel,
            "activityId": activityId,
            "fileName": fileName
        }
        response = requests.post(self.add_contract_url, json=add_contract_data, headers=headers)
        return response
